<template>
  <base-breadcrumb>
    <div class="page-detail">
      <searchData
        :search-data="searchArr"
        @search="search"
      />
      <a-card :bordered="false">
        <list-table
          ref="table"
          :columns="columns"
          :request="loadData"
          :export-config="{use:true,select:'风险要素清单选中',all:'风险要素清单全部'}"
          :export-permission="{select:'lcm_010_exp_03',all:'lcm_010_exp_03'}"
          :transform-time-key="['创建时间']"
        >
          <template
            slot="prefix"
            slot-scope="ref"
          >
            <a-button
              v-btn-permission="'lcm_010_add_02'"
              type="primary"
              icon="plus"
              @click="$router.push({path: 'add'})"
            >
              新增
            </a-button>
          </template>
          <span
            slot="index"
            slot-scope="text, record, index"
          >{{ index + 1 }}</span>
          <template
            slot="time"
            slot-scope="text, record, index"
          >
            {{ record.createTime|dateFormat('D') }}
          </template>
          <template
            slot="auditStatusStr"
            slot-scope="text, record, index"
          >
            <list-status
              :status="record.auditStatus"
              :text="text"
            />
          </template>
          <template
            slot="operation"
            slot-scope="text, record, index"
          >
            <MoreButton>
              <a
                v-btn-permission="'lcm_010_loo_01'"
                @click="$router.push({path: 'detail',query:{id:record.id}})"
              >查看</a>
              <a
                v-btn-permission="'lcm_010_edi_04'"
                @click="handleEdit(record, 1)"
              >编辑</a>
              <a
                v-if="record.auditStatus !== 'PAST'"
                v-btn-permission="'lcm_010_del_05'"
                @click="handleDel(record.id)"
              >删除</a>
            </MoreButton>
          </template>
        </list-table>
      </a-card>
    </div>
  </base-breadcrumb>
</template>

<script>
import elementCheckListApi from '@/api/legal/risk/elementCheckList'
import SelectDepartment2 from '@/views/Legal/risk/elementCheckList/components/SelectDepartment2'
export default {
  name: 'ElementCheckList',
  data() {
    return {
      columns: [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          scopedSlots: { customRender: 'index' }
        }, {
          title: '风险名称',
          dataIndex: 'riskName',
          width: '30%'
        },
        {
          title: '责任部门',
          dataIndex: 'orgName',
          width: 150
        },
        {
          title: '创建人',
          dataIndex: 'creatorName',
          width: 150
        },

        {
          title: '创建时间',
          dataIndex: 'createTime',
          scopedSlots: { customRender: 'time' },
          width: 120
        },
        {
          title: '状态',
          dataIndex: 'auditStatusStr',
          scopedSlots: { customRender: 'auditStatusStr' },
          width: this.STATUS_WIDTH
        },
        {
          title: '操作',
          width: 200,
          fixed: 'right',
          scopedSlots: { customRender: 'operation' }
        }
      ],
      searchArr: [
        // 搜索框
        {
          name: '风险名称',
          type: 'input',
          value: 'riskName'
        },
        {
          name: '责任部门',
          type: SelectDepartment2,
          valueKey: 'orgId'
        },
        {
          name: '创建人',
          type: 'input',
          value: 'creatorName'
        },
        {
          name: '创建时间',
          type: 'dateRangeFormat',
          value: 'createTime'
        },
        {
          name: '状态',
          type: 'select',
          value: 'auditStatus',
          data: [
            { label: '草稿', value: 'DRAFT', enabled: true },
            { label: '已归档', value: 'PAST', enabled: true }
          ]
        }
      ],
      loadData: (params) => {
        return elementCheckListApi.findListByMain({}, Object.assign(params, this.queryParam))
      },
      queryParam: {}
    }
  },
  methods: {
    search(val) {
      this.queryParam = val || {}
      if(this.queryParam.createTime&&this.queryParam.createTime.length) {
        this.queryParam.createTimeStartTime = new Date(this.queryParam.createTimeStartTime).getTime()
        // +" 00:00:00"
        this.queryParam.createTimeEndTime = new Date(this.queryParam.createTimeEndTime).getTime()
                // +" 23:59:59"
        this.queryParam.createTimeStart = new Date(this.queryParam.createTimeStart).getTime()
                // +" 00:00:00"
        this.queryParam.createTimeEnd = new Date(this.queryParam.createTimeEnd).getTime()
                // +" 23:59:59"
        delete this.queryParam.createTime
      }
      console.log( this.queryParam, ' this.queryParam')
      this.$refs.table.getData(null, true)
    },
    handleDel(id) {
      this.$delList2(elementCheckListApi.deleteByRiskFactors, () => {
        this.search()
      }, { ids: [id] })
    },
    handleEdit(record = {}, step) {
      this.$router.push({ path: 'add', query: { id: record.id } })
    }
  }
}
</script>
